package com.yc.project.servlet;

import com.google.gson.Gson;
import com.yc.project.dao.SearchDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "SearchServlet", value = "/search.s")
public class SearchServlet extends HttpServlet {

    SearchDao searchDao = new SearchDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String context=request.getParameter("context");
        String page = request.getParameter("page");
        if(page==null){
            page = "1";
        }
        Map<String,Object> dishs = searchDao.selectdish(context,page);
        String json = new Gson().toJson(dishs);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().append(json);
    }


}
